import request from '../request';

export const selectUserInfo = () => {
	return request({
		url: '/vilion/system/selectUserInfo',
		method: 'GET'
	});
}

export const updateUserInfo = userInfo => {
	return request({
		url: '/vilion/system/updateUserInfo',
		method: 'POST',
		data: userInfo
	});
}

export const addFeedback = (data) => {
	return request({
		url: '/vilion/system/addFeedback',
		method: 'POST',
		data
	})
}

export const getFeedbackRecords = (current, limit = 15) => {
	return request({
		url: '/vilion/system/getFeedback',
		method: 'GET',
		data: {
			current,
			limit
		}
	});
}

export const repliesFeedback = (feedbackId, replyContent) => {
	return request({
		url: '/vilion/system/repliesFeedback',
		method: 'POST',
		data: {
			feedbackId,
			replyContent
		}
	});
}

export const logout = () => {
	return request({
		url: '/vilion/system/logout',
		method: 'GET'
	})
}

export const selectAppUpdate = () => {
	return new Promise((resolve, reject) => {
		uni.getSystemInfo({
			success({
				osName
			}) {
				const clientType = osName === 'ios' ? 1 : 0;
				request({
					url: '/vilion/system/selectAppUpdate',
					method: 'GET',
					data: {
						clientType
					}
				}).then(res => resolve(res?.data)).catch(reject);
			},
			fail(err) {
				reject(err)
			}
		})
	})
}

export const getConnect = () => {
	return request({
		url: '/vilion/user/getConnect',
		ignoreToken: true,
		method: 'GET'
	})
}

// 账号与安全-重置密码V2.0（旧密码验证）
export const changePasswordByOldPassword = data => {
	return request({
		url: '/vilion/system/forgetPassword/changePasswordByOldPassword',
		method: 'POST',
		data
	})
}

// 账号与安全-重置密码V2.0（邮箱验证,获取验证码）
export const changePasswordByEmailGetCode = () => {
	return request({
		url: '/vilion/system/forgetPassword/changePasswordByEmailGetCode',
		method: 'POST',
	})
}

// 账号与安全-重置密码V2.0（邮箱验证,校验验证码）
export const changePasswordByEmailVerifyCode = code => {
	return request({
		url: '/vilion/system/forgetPassword/changePasswordByEmailVerifyCode',
		method: 'POST',
		data: {
			code
		}
	})
}

// 账号与安全-重置密码V2.0（邮箱验证）
export const changePasswordByEmail = data => {
	return request({
		url: '/vilion/system/forgetPassword/changePasswordByEmail',
		method: 'POST',
		data
	})
}

// 账号与安全-绑定邮箱V2.0（获取验证码）
export const getEmailCode = (email) => {
	return request({
		url: '/vilion/system/modifyEmail/getEmailCode',
		method: 'GET',
		data: {
			email
		}
	})
}

// 账号与安全-绑定邮箱V2.0（获取验证码）
export const modifyEmail = (data) => {
	return request({
		url: '/vilion/system/modifyEmail',
		method: 'POST',
		data
	})
}

// 注销
export const logoff = () => {
	return request({
		url: '/vilion/system/logoff'
	})
}

export const selectAppInfo = (version) => {
	return new Promise((resolve, reject) => {
		uni.getSystemInfo({
			success({
				osName
			}) {
				const clientType = osName === 'ios' ? 1 : 0;
				request({
					url: '/vilion/system/selectAppInfo',
					method: 'GET',
					data: {
						version: `V${version}`,
						clientType
					}
				}).then(res => resolve(res?.data)).catch(reject);
			},
			fail(err) {
				reject(err)
			}
		})
	})
}